package com.itstu.controller;

import com.itstu.model.AjaxResult;
import com.itstu.pojo.User;
import com.itstu.service.LoginService;
import com.itstu.utils.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 梁卓
 * @Version 1.0
 * @ClassName LoginController
 * @Description TODO
 * @Date 2024/09/27 22:01
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private LoginService loginService;

    /**
     * 登录接口
     * @param user 登录参数
     * @return 登录结果
     */
    @PostMapping
    public AjaxResult login(@RequestBody User user) {
        if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getPassword())) {
            return AjaxResult.error("用户名或密码不能为空");
        }
        String token = loginService.login(user);
        return AjaxResult.success(token);
    }

}
